import { Global, Module } from '@nestjs/common';
import { TypegooseModule } from 'nestjs-typegoose/dist/typegoose.module';
import { DbService } from './db.service';
import { Action } from './models/action.model';
import { Banner } from './models/banner.model';
import { Personage } from './models/personage.model';
import { User } from './models/User.model';
import { Works } from './models/works.model';
import { Comment } from './models/comment.model';
import { Say } from './models/say.model';
import { Wallpaper } from './models/wallpaper.model';

const models = TypegooseModule.forFeature([
  User,
  Personage,
  Works,
  Banner,
  Action,
  Comment,
  Say,
  Wallpaper
])

@Global()
@Module({
  imports: [
    TypegooseModule.forRootAsync({
      useFactory(){
        return {
          uri: process.env.DB,
          useNewUrlParser: true,
          useUnifiedTopology: true,
          useCreateIndex: true,
          useFindAndModify: false
        }
      }
    }),
    models
  ],
  providers: [DbService],
  exports: [DbService, models],
})
export class DbModule {}
